﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MsTestUtilities.Errors
{
    internal class ErrorCollector
    {
        private List<string> _errors = new List<string>();

        public void AddError(string errorMessage)
        {
            _errors.Add(errorMessage);
        }

        public void Evaluate()
        {
            Evaluate(string.Format("{0} assertion(s) failed:", _errors.Count));
        }

        public void Evaluate(string failedTitleMessage)
        {
            if (_errors.Any())
            {
                StringBuilder errorMessageBuilder = new StringBuilder(failedTitleMessage);
                errorMessageBuilder.AppendLine();
                _errors.ForEach(e => errorMessageBuilder.AppendLine(e));                
                throw new AssertFailedException(errorMessageBuilder.ToString());
            }
        }
    }
}
